package com.hzit.servlet.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.Date;
import java.util.UUID;

@WebServlet(name = "BServlet", urlPatterns = "/cookie/Bservlet")
public class BServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建cookie,请求时候只要是该服务器的cookie, 都会自动的携带给服务器

        Cookie[] cookies = req.getCookies();
        HttpSession session = req.getSession();//如果有直接返回，如果没有创建一个新的回话

       resp.getWriter().println("------->JSSESIONID:"+session.getId());

        if (cookies != null) {

            for (Cookie cookie : cookies) {

                //cookie本身就是一个键值对
                String name = cookie.getName();
                String value = cookie.getValue();

                resp.getWriter().println("cookie 的名称:" + name + " values:" + value);
            }


        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
